class Solution {
public:
    int StrToInt(string str)
    {

        int flag = 1, ret = 0;
        if (str[0] == '-') flag = -1;

        for (int i = 0; i < str.size(); i++)
        {
            if (str[i] == '+' || str[i] == '-') continue;
            if (str[i] >= '0' && str[i] <= '9')
                ret += pow(10, str.size() - i - 1) * (str[i] - '0');
            else
                return 0;
        }

        return ret * flag;
    }
};